<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <title>欢迎页面-X-admin2.2</title>
    <script th:replace="~{layout/common-head :: head}"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-form">
            <div class="layui-form-item">
                <label for="title" class="layui-form-label">
                    <span class="x-red">*</span>菜单标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title" name="title" required="" lay-verify="required"
                           th:value="${menu!=null?menu.title:''}" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="code" class="layui-form-label">
                    <span class="x-red">*</span>菜单编码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="code" name="code" required="" lay-verify="required"
                           th:value="${menu!=null?menu.code:''}" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>唯一的编码
                </div>
            </div>
            <div class="layui-form-item">
                <label for="url" class="layui-form-label">
                    菜单URL
                </label>
                <div class="layui-input-block">
                    <input type="text" id="url" name="url"
                           th:value="${menu!=null?menu.url:''}" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="seq" class="layui-form-label">
                    <span class="x-red">*</span>排序号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="seq" name="seq" required="" lay-verify="number"
                           th:value="${menu!=null?menu.seq:'1'}" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    排序的位置
                </div>
            </div>
            <div class="layui-form-item">
                <label for="icon" class="layui-form-label">
                    <span class="x-red">*</span>菜单图标
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="icon" name="icon" required="" lay-verify="required"
                           th:value="${menu!=null?menu.icon:'layui-icon layui-icon-right'}" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" style="cursor: pointer"
                     onclick="window.open('/assets/html/icon.html')">
                    <i id="showIcon" class="layui-icon layui-icon-right"></i>
                    点击查看图标库
                </div>
            </div>
            <div class="layui-form-item">
                <label for="description" class="layui-form-label">
                    备注/描述
                </label>
                <div class="layui-input-block">
                    <textarea name="description" id="description" placeholder="请输入备注/描述" class="layui-textarea"
                              style="min-height: 65px">[[${menu!=null?menu.description:'一级菜单'}]]</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button class="layui-btn" lay-filter="edit" lay-submit>立即提交</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        $('#icon').blur(function () {
            var icon = $(this).val();
            $('#showIcon').removeClass()
            $('#showIcon').addClass(icon)
        });

        //监听提交
        form.on('submit(edit)', function (data) {
            app.ajax({
                data: data.field,
                type: 'post',
                url: "[[${menu!=null?'/menu/editParentMneu':'/menu/addParentMneu'}]]",
                success(data) {
                    if (data.code == 0)
                        layer.alert(data.msg, {
                                icon: 6
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                }
            })
            return false;
        });
    });
</script>
</body>

</html>
